/**
 * 控制tabs菜单位置
 */
const useContextMenu = () => {
	/**
	 * 选中的数据
	 */
	const chooseValue = ref<AuthRoute.Route>({
		path: '',
		name: '',
	});
	/**
	 * 控制显示
	 */
	const show = ref(false);
	/**
	 * 选中的下标
	 */
	const chooseIndex = ref(0);
	/**
	 * 位置信息
	 */
	const position = ref({
		top: 0,
		left: 0,
	});
	/**
	 * 显示菜单
	 * @param{MouseEvent} e
	 * @param{T} item
	 */
	const openMenu = (e: MouseEvent, item: AuthRoute.Route, index: number) => {
		show.value = true;
		chooseIndex.value = index;
		chooseValue.value = item;
		position.value.top = e.pageY + 4;
		position.value.left = e.pageX + 4;
		window.addEventListener('click', closeMenu);
	};
	/**
	 * 关闭菜单显示
	 */
	const closeMenu = () => {
		if (!show.value) return;
		show.value = false;
		window.removeEventListener('click', closeMenu);
	};
	return {
		show,
		chooseIndex,
		position,
		openMenu,
		chooseValue,
	};
};
export default useContextMenu;
